package com.maple.util.thread;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

@Data
@Accessors(chain = true)
public class RelationVO {

    private String id;

    private String fromId;

    private String toId;

    private static void printInfo(String data) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.print(data + "==");
    }

    private static void printByCompletableFuture(List<String> dataList) {
        long start = System.currentTimeMillis();
        Runnable[] tasks = new Runnable[dataList.size()];
        for (int i = 0; i < dataList.size(); i++) {
            String data = dataList.get(i);
            tasks[i] = () -> {
                printInfo(data);
            };
        }
        //执行任务
        CompletableFutureSimpleThreadPool.executeTasks(tasks);
        System.out.println("耗时printByCompletableFuture:" + (System.currentTimeMillis() - start));
    }

    private static void print(List<String> dataList) {
        long start = System.currentTimeMillis();
        for (String data : dataList) {
            printInfo(data);
        }
        System.out.println("耗时print:" + (System.currentTimeMillis() - start));
    }

    public static void main(String[] args) {
        List<String> dataList = List.of("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31",
                "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
        // print(dataList);

        printByCompletableFuture(dataList);
    }
}
